package popcorn.ticket.serviceimpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import popcorn.ticket.dao.LogsMapper;
import popcorn.ticket.entity.Logs;
import popcorn.ticket.service.LogsService;
import popcorn.ticket.tool.PageData;

@Service
public class LogsServiceImpl implements LogsService {

	@Autowired
	private LogsMapper lm;

	/**
	 * 根据用户编号查询+时间区间查询
	 */
	@Override
	public PageData<Logs> selectLogsByUserid(int userid, int page, int limit,String startTime,String endTime) {
		// 开启分页
		PageHelper.startPage(page, limit);
		List<Logs> list = lm.selectLogsByUserid(userid, startTime, endTime);

		PageInfo<Logs> pageInfo = new PageInfo<>(list);
		PageData<Logs> pd = new PageData<>(list, page, (int) pageInfo.getTotal(), limit);

		pd.setCode(0);
		pd.setMsg("");

		return pd;
	}


	@Override
	public boolean insertLogs(Logs logs) {
		int n = lm.insert(logs);
		if (n > 0) {
			return true;
		} else {
			return false;
		}
	}

}
